package com.jj.util;

import java.util.ArrayList;
import java.util.List;

public class StringUtil {

	public static String genRandomString() {
		return null;
	}
	
	
	public static String genRandomString(int min, int max) {
		char[] list = new char[62];
		int count = 0;
		for(int i=48; i<=57; i++) {
			list[count++] = (char)i;
		}
		for(int i=65; i<=90; i++) {
			list[count++] = (char)i;
		}
		for(int i=97; i<122; i++) {
			list[count++] = (char)i;
		}
		int sub = max - min + 1;
		// TODO 长度随机有待改进
		int l = (int)(Math.random() * max * 10) % sub;
		int len = min + l - 1;
		if(len<min)
			len = min;
		String result = "";
		for(int i=0; i<len; i++) {
			int index = (int)(Math.random()*1000) % list.length;
			result += list[index];
		}
		return result;
	}

	/**
	 * 判断字符是否是空，空字符串也判断为空
	 * @param s
	 * @return
	 */
	public static boolean isEmpty(String s) {
		if(s==null || s.length()==0)
			return true;
		else
			return false;
	}

	/**
	 * 首字母转小写
	 */
	public static String toLowerCaseFirstOne(String s){
		if(Character.isLowerCase(s.charAt(0)))
			return s;
		else
			return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString();
	}

	/**
	 * 首字母转大写
	 * @param s
	 * @return
	 */
	public static String toUpperCaseFirstOne(String s){
		if(Character.isUpperCase(s.charAt(0)))
			return s;
		else
			return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
	}

	/**
	 * 将,分隔的数字转成long列表
	 * 如1,2,3
	 * @param nums
	 * @return
	 */
	public static List<Long> toLongList(String nums) {
		List<Long> numList = new ArrayList<Long>();
		String[] numS = nums.split(",");
		for(String num : numS) {
			numList.add(Long.parseLong(num));
		}
		return numList;
	}
	/**
	 * 将,分隔的数字转成int列表
	 * 如1,2,3
	 * @param nums
	 * @return
	 */
	public static List<Integer> toIntegerList(String nums) {
		List<Integer> numList = new ArrayList<Integer>();
		String[] numS = nums.split(",");
		for(String num : numS) {
			numList.add(Integer.parseInt(num));
		}
		return numList;
	}
	public static void main(String[] args) {
		char a = 'a';
		char z = 'z';
		char A = 'A';
		char Z = 'Z';
		char n0 = '0';
		char n9 = '9';
		
		System.out.println((int)a);
		System.out.println((int)z);
		System.out.println((int)A);
		System.out.println((int)Z);
		System.out.println((int)n0);
		System.out.println((int)n9);
		
		System.out.println("来");
		System.out.println(genRandomString(1,10));
	}
}
